package com.itheima.d1_algorithm.CaseTest;

/**
 * @ClassName erFenChaoZhao
 * @Author 16799
 * @Date 2025/7/22 9:19
 * @Version 1.0
 * @Description TODO
 **/
public class erFenChaoZhao {
    public static void main(String[] args) {
        int arr[] = {1,33,43,57,58,67,77,78};

        int index = binary(arr,99);
        System.out.println(index);

    }

    private static int binary(int arr[],int data){
        int left = 0;
        int right = arr.length-1;

        while (left<=right){
            int middle = (left+right)/2;
            if (arr[middle]<data){
                left = middle+1;
            }else if (arr[middle]>data){
                right = middle-1;
            }else {
                return middle;
            }
        }
        return -1;
    }
}
